<template>
  <div class="body">
    <header class="header">
      <div class="title">
        <!-- <router-link to="/xqda"> -->
        <img src="../../assets/images/01_11.png" alt class="img_zuo" @click="toback" />
        <div>{{title}}监督检查计划</div>
      </div>
    </header>
    <div class="contant">
      <!--<van-pull-refresh v-model="refreshing" @refresh="onRefresh">-->
        <van-list v-model="loading" :finished="finished" @load="onLoad">
          <div  class="xcbs_box" v-for="(v,index) of list" :keys="index" @click="openDetail(v)">
            <div class="xcbs_child">
               <img class="img_persons" v-if="v.patrolTroubleshootId>0||(v.patrolTroubleshootId==0&&v.noweInfoId>0)" src="../../assets/images/logo5.png" />
                <img class="img_persons" v-if="v.commitId>0" src="../../assets/images/rwls.png" />
              <div class="xcbs_suns">
                <div class="xcbs_sunsn">
                  <div class="xcbs_tit1" v-if="v.type!==''">[{{v.type}}]</div>
                <div class="xcbs_tit">{{v.unitsName}}&nbsp;</div>
                </div>
                 
                <div class="xcbs_sun">
                  <img v-show="getStatus(v.isRectifica)=='黄灯'&&!(v.commitId>0)" class="yh_light" src="../../assets/images/jsd.gif" />
                  <img v-show="getStatus(v.isRectifica)=='勾'&&!(v.commitId>0)" class="yh_light" src="../../assets/images/lg.png" />
                  <img class="img_people" src="../../assets/images/people.png" />
                  <div>{{v.ptPerson}}</div>
                </div>
              </div>
            </div>
            <div class="time">{{v.niAddtime}}</div>
          </div>

        </van-list>
      <!--</van-pull-refresh>-->
    </div>
  </div>
</template>

<script>
  // import  Tabbar from '../../tabbar'
  import utils from "../../assets/js/utils.js"
  export default {
    name: 'jdjc_list',
    data() {
      return {
        userId: null, //用户id
        list: [],
        where: '',
        leibielist: [], //方式
        loading: false, //加载状态结束false
        finished: false, //全部加载完成true
        error: false, //出错状态
        refreshing: false, //是否下拉加载 是true
        cunt: 1,
        yinchang: false,
        scroll: 0,
        total: null,
        src: '',
        jdjc_params:{},//列表参数，包括页面返回路由
        load_over:false,
        page:1,
        pageSize:50,
        title:''
      }
    },
    components: {
      // Tabbar
    },
    methods: {
      toback() {
        // if(this.checkNull(this.jdjc_params.from)){
        //   this.$router.push("/index");
        // }else{
        //   this.$router.push(this.jdjc_params.from);
        // }
        this.$router.back()
      },
      getStatus(status){
        var str = '';
        if(status||status===0){
          if(status===1||status===3||status===6){
            str = '勾';
          }else{
            str = '黄灯';
          }
        }
        return str;
      },
      getTime(time){
        return utils.dateFormat(time,'MM-DD');
      },
      getlist() {
        var _this = this;
        /*try {
          plus.nativeUI.showWaiting("正在加载...");
        } catch (e) {
          console.log(e.message);
        }*/
        var sj_flag = false;
        var url = _this.$global_msg.Url.host+'/monitoringPlan/planList?type='+_this.jdjc_params.type;
        if(_this.jdjc_params.type=='隐患列表'){
          url = _this.$global_msg.Url.host+'/SupervisionExamine/selectPatrolList?ptId='+_this.jdjc_params.ptId;
        }else{
          if(!_this.checkNull(_this.jdjc_params.month)){
            sj_flag = true;
            url = _this.$global_msg.Url.host+'/SupervisionExamine/selectSupervisionByRandomList?';
            url+='month='+_this.jdjc_params.month;
          }else{
            url+='&page='+_this.page;
            url+='&pageSize='+_this.pageSize;
          }
          var dwId = null;
          if(!_this.checkNull(_this.jdjc_params.dwId)){
            dwId = _this.jdjc_params.dwId;
          }
          if(!_this.checkNull(_this.jdjc_params.sqId)){
            dwId = _this.jdjc_params.sqId;
          }
          if(dwId||dwId===0){
            url+='&dwId='+dwId;
          }
          url+='&userId='+_this.userId;
        }
        _this.axios.get(
          url, {
            headers: {
              "Content-Type": "application/json"
            }
          }).then(res => {
            console.log(res.data);
            if(res.data.code==200){
              if(_this.jdjc_params.type=='隐患列表'||sj_flag){
                if(res.data.rows){
                  _this.list = _this.list.concat(res.data.rows);
                }
                if(_this.list.length==0){
                  _this.$toast('暂无数据');
                }
                _this.finished = true;
              }else{
                if(res.data.rows&&res.data.rows.list){
                  _this.list = _this.list.concat(res.data.rows.list);
                }
                if(_this.list.length==0){
                  _this.$toast('暂无数据');
                }
                if(_this.list.length>=res.data.rows.total){
                  _this.finished = true;
                }else{
                  _this.page++;
                }
              }
            }else{
              _this.$toast(res.data.msg);
              _this.finished = true;
            }
            // 加载状态结束
            _this.loading = false;
            _this.load_over = true;


            try {
              plus.nativeUI.closeWaiting();
            } catch (e) {
              console.log(e.message);
            }
        }).catch(err=>{
             _this.$terminal._error(err)
          })
      },

      onLoad() {
        // 异步更新数据
        // this.yc = true
        if (this.refreshing) {
          this.list = [];
          this.page = 1
          this.refreshing = false;
        }
        // for (let i = 0; i < 20; i++) {
        //   this.list.push(this.list.length + 1);
        // }
        this.getlist()


        // 出错
        // if (this.cunt >= 2) {
        //     this.error = true;
        // }
        // 数据全部加载完成
      },
      onRefresh() {
        console.log("下拉")
        // 清空列表数据
        this.finished = false;
        // this.yc=false
        // 重新加载数据
        // 将 loading 设置为 true，表示处于加载状态
        this.loading = true;
        this.page = 1
        this.onLoad();
      },
      checkNull(value){//检测是否为空
        if(value||value===0||value==='0'){
          return false;
        }else{
          return true;
        }
      },
      openDetail(v){
        /*var jdjc_detail_params = {
          from:'/jdjc_list',
          patrolTroubleshootId:v.patrolTroubleshootId,
          patrolTroubleshootInfoId:v.patrolTroubleshootInfoId
        };
        //测试
        //jdjc_detail_params.patrolTroubleshootId = 4178;
        //jdjc_detail_params.patrolTroubleshootInfoId = 13392;
        localStorage.setItem("jdjc_detail_params",JSON.stringify(jdjc_detail_params));
        localStorage.setItem("jdjc_list_scrollTop",$('.contant').scrollTop());
        this.$router.push("/jdjc_detail");*/

        sessionStorage.setItem("inspection_patrolTroubleshootId", v.patrolTroubleshootId);
        sessionStorage.setItem("inspection_infoId", (v.patrolTroubleshootInfoId||v.patrolTroubleshootInfoId===0)?v.patrolTroubleshootInfoId:'');
        localStorage.setItem("hard_detail_from",'/jdjc_list');
        localStorage.setItem("jdjc_list_scrollTop",$('.contant').scrollTop());
        //this.$router.push("/hard_detail");
      
        if (v.patrolTroubleshootId>0) {
          // this.$router.push("/hard_detail");
            // sessionStorage.setItem("inspection_patrolTroubleshootId", ptId);
            // sessionStorage.setItem("inspection_infoId", infoId);
            this.$router.push("/hard_detail");
          } else if (v.patrolTroubleshootId==0&&v.noweInfoId>0){
            this.$router.push({
              path: "/ptlook",
              query: { id: v.noweInfoId, ids: 14 },
            });
          }else if(v.patrolTroubleshootId==0&&v.noweInfoId==0){
             this.$router.push({
              path: "/jdjc_luoshi",
              query: { id: v.commitId },
            });
          }
      }
    },
    //进入该页面时，用之前保存的滚动位置赋值
    beforeRouteEnter (to, from, next) {
        next(vm => {
          var jdjc_list_scrollTop = localStorage.getItem("jdjc_list_scrollTop");
          if(vm.checkNull(jdjc_list_scrollTop)){//进入页面。刷新列表
            vm.userId = localStorage.getItem("userId") //获取访问id
            vm.jdjc_params = localStorage.getItem("jdjc_params")?JSON.parse(localStorage.getItem("jdjc_params")):{};

            var jdjc_title=sessionStorage.getItem("jdjc_title");
            var jdjc_table_title=sessionStorage.getItem("jdjc_table_title");
            if(jdjc_table_title||jdjc_table_title===0){
              vm.title = jdjc_table_title;
            }else{
              vm.title = (jdjc_title||jdjc_title===0)?jdjc_title:'渝中区';
            }

            if(vm.load_over){
              vm.list = [];
              vm.refreshing = false;
              vm.page = 1;
              vm.onRefresh();
            }
          }else{//从详情返回
            $('.contant').animate({scrollTop: jdjc_list_scrollTop}, 0);
            localStorage.removeItem("jdjc_list_scrollTop");
          }
        })
    },
    mounted() {
      var _this = this;
      document.body.style.backgroundColor = "#F7F7F9";
      //物理返回
      // window.addEventListener("popstate", function(){
      //   _this.toback();
      // }, false);
    },
    created() {

    }
  }
</script>

<style scoped>
  .body{
    width: 100%;
    height: 100%;
    position: fixed;
    top: 0;
    left: 0;
    display: flex;
    flex-direction: column;
  }
 /* 头部开始 */
  .header {
    height: 1.8519rem;
    background: #007aff;
    padding-top: 0.8333rem;
    box-sizing: border-box;
    width: 100%;
    z-index: 20;
    font-size: 0.388888rem;
  }

  .title {
    padding: 0 0.3704rem;
    display: flex;
    align-items: center;
    color: #fff;
  }

  .btn-change {
    position: absolute;
    left: 1.537037rem;
    font-size: 0.488888rem !important;
    bottom: 0px;
    top: 0.15rem;
    width: auto !important;
    height: 100%;
    display: -webkit-box;
    display: -ms-flexbox;
    display: flex;
    -webkit-box-align: center;
    -ms-flex-align: center;
    align-items: center;
  }

  .title>div {
    width: 100%;
    font-size: 0.4444rem;
    text-align: center;
  }

  .img_zuo {
    width: 0.2593rem;
    height: 0.463rem;
  }

  /* 头部结束 */
  .contant{
    flex: 1;
    width: 100%;
    overflow-y: scroll;
  }
  .posi {
    display: flex;
    flex-wrap: wrap;
    position: fixed;
    top: 1.8519rem;
    width: 100%;
    background: #fff;
    z-index: 10;
  }

  .styles {
    display: inline-block;
    /* border: 1px solid blue; */
    width: 19.6%;
    font-size: 0.25rem;
    margin-bottom: 0.2rem;
  }

  .hdgd {
    text-align: center;
    display: flex;
    justify-content: center;
    flex-direction: column;
    align-items: center;
  }

  .hdgd div {
    display: inline-block;
  }

  .styles div {
    margin-top: 0.1rem;
  }

  .rvvee {
    width: 100%;
  }

  .stylebox {
    background: white;
    padding: 0.37037rem;
    box-sizing: border-box;
    /* border: 1px solid red; */
  }

  .img_log6 {
    width: 0.8rem;
    display: inline-block;
  }

  .img_people {
    width: 0.3519rem;
    margin-right: 0.2rem;
    height: 0.3519rem;
  }

  .xcbs_suns {
    width: 85%;
    /* border: 1px solid red; */
    margin-left: 0.3rem;
    margin-top: 0.15rem;
  }
.xcbs_sunsn{
display: flex;
}
  .xcbs_sun {
    display: flex;
    align-items: center;
    font-size: 0.296296rem;
    color: #999;
    margin-top: 0.092592rem;
  }

  .time {
    font-size: 0.35rem;
  }

  .xcbs_tit {
    font-size: 0.35rem;
    width:70%;
    /* border: 1px solid red; */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }
  .xcbs_tit1 {
    font-size: 0.35rem;
    /* width:17%; */
    /* border: 1px solid red; */
    white-space: nowrap;
    overflow: hidden;
    text-overflow: ellipsis;
  }

  .img_persons {
    width: 0.6667rem;
    height: 0.7407rem;
  }

  .xcbs_child {
    /* border: 1px solid blue; */
    width: 85%;
    display: flex;
    align-items: center;
  }

  .listvr {
    margin-top: 0.2rem;
  }

  .xcbs_box {
    display: flex;
    justify-content: space-between;
    height: 1.388888rem;
    border-radius: 0.15rem;
    align-items: center;
    background-color: white;
    padding: 0 0.4rem;
  }

  .listvr_tit {
    border-radius: 0.15rem;
    padding: 0 0.4rem;
    height: 0.8rem;
    background-color: white;
    line-height: 0.8rem;
    border-bottom: 1px solid #DDDDDD;
  }



  .header {
    height: 1.8519rem;
    background: #007aff;
    padding-top: 0.8333rem;
    box-sizing: border-box;
    width: 100%;
    z-index: 20;
    font-size: 0.388888rem;
  }

  .title {
    padding: 0 0.3704rem;
    display: flex;
    align-items: center;
    color: #fff;
  }

  .title>div {
    width: 100%;
    font-size: 0.4444rem;
    text-align: center;
  }

  .img_zuo {
    width: 0.2593rem;
    height: 0.463rem;
  }

  .img_big {
    width: 0.629629rem;
  }

  .yh_light{
    width: 0.37037rem !important;
    height: 0.37037rem !important;
    margin-right: 0.2rem;
  }
</style>
